package com.wtwd.device.controller;


import com.wtwd.device.constant.RespCode;
import com.wtwd.device.model.dto.DeviceBloodOxygenTotalDto;
import com.wtwd.device.model.dto.SynchronizationBloodOxygenDto;
import com.wtwd.device.model.entity.DeviceBloodOxygen;
import com.wtwd.device.model.entity.DeviceBloodOxygenTotal;
import com.wtwd.device.model.vo.DeviceBloodOxygenTotalVo;
import com.wtwd.device.model.vo.ResultVO;
import com.wtwd.device.service.AppDeviceBloodOxygenService;
import com.wtwd.device.service.AppDeviceBloodOxygenTotalService;
import com.wtwd.device.util.DateUtils;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

@Api(tags = "血氧模块")
@RestController
@RequestMapping("/app-blood-oxygen")
public class AppDeviceBloodOxygenController {


    @Resource
    private AppDeviceBloodOxygenTotalService appDeviceBloodOxygenTotalService;

    @Resource
    private AppDeviceBloodOxygenService deviceBloodOxygenService;

    @ApiOperation("获取某一天的血氧信息及血氧详细信息(一般血氧)")
    @ApiImplicitParams({@ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "long"), @ApiImplicitParam(name = "date", value = "日期,yyyyMMdd", required = true, dataType = "String"), @ApiImplicitParam(name = "id", value = "血氧详细信息表主键id 默认不传查全天", required = false, dataType = "long")})
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")})
    @GetMapping("/getDayBloodOxygenByTime")
    public ResultVO<DeviceBloodOxygenTotalVo> getDayBloodOxygenByTime(@RequestParam String date, @RequestParam Long deviceId, @RequestParam(value = "id", required = false) Long id) {
        DeviceBloodOxygenTotalVo deviceHeartRateTotalVo = appDeviceBloodOxygenTotalService.getDayBloodOxygenByTime(deviceId, id, date);
        return ResultVO.success(deviceHeartRateTotalVo);
    }


    @ApiOperation(value = "根据开始日期和结束日期获取血氧统计信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = false, dataType = "long")
            , @ApiImplicitParam(name = "startDate", value = "开始日期,yyyyMMdd", required = true, dataType = "String")
            , @ApiImplicitParam(name = "endDate", value = "结束日期,yyyyMMdd", required = true, dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @GetMapping("/getDaysBloodOxygenTotal")
    public ResultVO<List<DeviceBloodOxygenTotal>> getDaysBloodOxygenTotal(@RequestParam Long deviceId, @RequestParam String startDate, @RequestParam String endDate) {
        List<DeviceBloodOxygenTotal> deviceBloodOxygenTotals = appDeviceBloodOxygenTotalService.getDaysBloodOxyge(deviceId, startDate, endDate);
        return ResultVO.success(deviceBloodOxygenTotals);
    }

    /**
     * 同步血氧数据
     *
     * @return
     */
    @ApiOperation("同步血氧数据")
    @PostMapping("/synchronizationBloodOxygen")
    public ResultVO<List<DeviceBloodOxygenTotal>> synchronizationBloodOxygen(@RequestBody SynchronizationBloodOxygenDto dao) {
        List<DeviceBloodOxygenTotal> deviceBloodOxygenTotals = appDeviceBloodOxygenTotalService.synchronizationBloodOxygen(dao.getDeviceBloodOxygenTotalDtos());
        return ResultVO.success(deviceBloodOxygenTotals);
    }


}
